//
//  ComposeImageView.m
//  SinaWebo
//
//  Created by wwj on 16/1/14.
//  Copyright © 2016年 亦心. All rights reserved.
//

#import "ComposeImageView.h"

@implementation ComposeImageView

+(instancetype)composeImageView{
    return [[self alloc] init];
}

+(instancetype)composeImageView:(UIImage *)image{
    return [[ComposeImageView composeImageView] initWithImage:image];
}

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self initView];
    }
    return self;
}

-(void)initView{
    self.contentMode = UIViewContentModeScaleAspectFill;
    
    self.layer.frame = self.frame;
    self.layer.masksToBounds = YES;
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setImage:[UIImage imageNamed:@"compose_photo_close"] forState:UIControlStateNormal];
    
    [self addSubview:btn];
}

-(void)layoutSubviews{
    [super layoutSubviews];
    UIButton *btn = self.subviews.lastObject;
    btn.frame = CGRectMake(self.frame.size.width - btn.frame.size.width, 0, 17, 17);
    [btn addTarget:self action:@selector(onClickButton:) forControlEvents:UIControlEventTouchUpInside];
}

-(void)onClickButton:(UIButton *)btn{
    [self removeFromSuperview];
}

@end
